package com.museum.guide.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.museum.guide.common.result.Result;
import com.museum.guide.entity.AppointmentTimeSlot;
import com.museum.guide.service.AppointmentTimeSlotService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/timeSlot")
public class AppointmentTimeSlotController {

    @Resource
    private AppointmentTimeSlotService timeSlotService;

    /**
     * 分页查询时间段信息
     */
    @GetMapping("/page")
    public Result<Page<AppointmentTimeSlot>> page(
            Page<AppointmentTimeSlot> page,
            String name,
            String period,
            Integer status) {
        return Result.success(timeSlotService.page(page, name, period, status));
    }

    /**
     * 获取所有可用的时间段列表
     */
    @GetMapping("/listEnabled")
    public Result<List<AppointmentTimeSlot>> listEnabled() {
        return Result.success(timeSlotService.listEnabled());
    }

    /**
     * 根据时段获取时间段列表
     */
    @GetMapping("/listByPeriod")
    public Result<List<AppointmentTimeSlot>> listByPeriod(@RequestParam String period) {
        return Result.success(timeSlotService.listByPeriod(period));
    }

    /**
     * 新增时间段
     */
    @PostMapping("/add")
    public Result<Void> save(@RequestBody @Valid AppointmentTimeSlot timeSlot) {
        timeSlotService.saveTimeSlot(timeSlot);
        return Result.success();
    }

    /**
     * 更新时间段信息
     */
    @PostMapping("/update")
    public Result<Void> update(@RequestBody @Valid AppointmentTimeSlot timeSlot) {
        timeSlotService.updateTimeSlot(timeSlot);
        return Result.success();
    }

    /**
     * 删除时间段
     */
    @DeleteMapping("/removeById")
    public Result<Void> remove(Long id) {
        timeSlotService.removeTimeSlot(id);
        return Result.success();
    }

    /**
     * 启用/禁用时间段
     */
    @PostMapping("/updateStatus")
    public Result<Void> updateStatus(@RequestParam Long id, @RequestParam Integer status) {
        timeSlotService.updateStatus(id, status);
        return Result.success();
    }
}